package jike.demo56.test02;

import jike.demo56.test01.UserService;

import java.util.ArrayList;
import java.util.List;

/**
 * @param
 * @author oyz
 * @version 1.0.4
 * @description:TODO
 * @date 2023/5/18 21:03
 */
public class UserController {

    private UserService userService;

    private static List<RegObserver> observers = new ArrayList<>();

    public void setRegObservers(RegObserver observers) {
        this.observers.add(observers);
    }


    public void register(String username, String password){

        String userId = userService.registerUser(username, password);
        // 在注册用户之后新增两种不同的逻辑，同时不影响到主的业务
        setRegObservers(new EmailDeal());
        setRegObservers(new MessageDeal());
        observers.forEach(observer ->{
           observer.handleRegSuccess(Long.valueOf(userId));
        });
    }

}
